#!/bin/bash

WIKIDIR=/storage/twiki
BACKUPDIR=/storage/backup
FILE_LOG=$BACKUPDIR/wiki-backup.log

SEQ=`date +%Y%m%d-%H%M`

find $WIKIDIR/* -maxdepth 1 -name '*iki*' -a ! -name '*.log' -type f|xargs rm -f

if [ -e $FILE_LOG ]; then
        echo -e "-----------------\nremovendo os backups anteriores em $SEQ" >> $FILE_LOG
fi

find $WIKIDIR/* -maxdepth 1 -name '*iki*' -type d | while read a; do tar -cf $BACKUPDIR/`echo $a|awk -F/ '{print $4}'`.tar $a; done

if [ ! -e $FILE_LOG ]; then
	echo -e "=================\nbackup realizado em $SEQ" > $FILE_LOG
else
	echo -e "-----------------\nbackup realizado em $SEQ" >> $FILE_LOG
fi

